//
//  BaseTabbarController.m
//  OPEN
//
//  Created by 净邻 on 2016/10/20.
//  Copyright © 2016年 净邻. All rights reserved.
//

#import "BaseTabbarController.h"
#import "BaseNavController.h"
//#import "UserDefaultsUtil.h"
#import "LoginViewController.h"

@interface BaseTabbarController ()<UITabBarControllerDelegate>

@end

@implementation BaseTabbarController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.delegate = self;
    [self.tabBar setTranslucent:NO];
    [[UITabBar appearance] setBarTintColor:[UIColor whiteColor]];
}

- (void)addTitle:(NSString *)title icon:(NSString *)icon selectIcon:(NSString *)selectIcon controller:(UIViewController *)controller {
    
    //Tabbar设置
    controller.title = title;
    controller.tabBarItem = [[UITabBarItem alloc] initWithTitle:title image:[UIImage imageNamed:icon] selectedImage:[UIImage imageNamed:selectIcon]];
    
    //未选择颜色
    [[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:HexRGB(0x585858)} forState:UIControlStateNormal];

    //选择颜色
    [[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:HexRGB(0x35A5FC)} forState:UIControlStateSelected];
    
    //NAV设置
    BaseNavController *baseNavController = [[BaseNavController alloc] initWithRootViewController:controller];
//    baseNavController.navigationBarHidden = YES;

    [self addChildViewController:baseNavController];
}

- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item {
//    if([item.title isEqualToString:@"我的"]){
//        NSString *sid = [[FileOperator defaultOperator] userInfoObjectForKey:@"sid"];
//        if (sid&&![sid isEqualToString:@""]) {
//        }else{
//            LoginViewController *loginViewController = [[LoginViewController alloc] init];
//            [self presentViewController:loginViewController animated:YES completion:nil];
//        }
//
//    }
}

#pragma mark- UITabBarControllerDelegate
-(BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController{
    
//    NSString *sid = [[FileOperator defaultOperator] userInfoObjectForKey:@"sid"];
//
//    if (viewController == self.viewControllers[2]) {
//        if (sid&&![sid isEqualToString:@""]) {
//            return YES;
//        }else{
//            return NO;
//        }
//    }else{
//        return YES;
//    }
    
    return YES;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

@end
